<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta charset="UTF-8">
    <title>Bob Website</title>
</head>

<body>
    <div></div>
    <button id="btn1">按钮1</button>
    <button id="btn2">按钮2</button>
    <div id="content">测试内容太</div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="./js/dialog.js"></script>
    <script>
        var d1 = new CtoDialog({
            id: 'dialog1',
            showClose: true,
            title: '提示',
            content: document.getElementById('content'),
            showBtn: true,
            btnCallback: function(type) {
                this.hide();
            }
        });

        var d2 = new CtoDialog({
            id: 'dialog2',
            showClose: true,
            title: '请选择对应课程的优惠券',
            content: document.getElementById('content'),
        });
        document.getElementById('btn1').onclick = function() {
            // d1.show();
            debounce(function() {
              console.log('防抖打印');
            }, 5000);
            
        }

        let timer = 0;
        function debounce(fn, time, defer) {
          if (!defer) {
            if (!timer) {
              fn();
            } else {
              clearTimeout(timer);
            }

            timer = setTimeout(() => {
              timer = null;
            }, time);
          } else {
            clearTimeout(timer);
            timer = setTimeout(fn, time);
          }
        }

        document.getElementById('btn2').onclick = function() {
            d2.show();
        }
    </script>
</body>

</html>